package com.lianrui.app.member.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lianrui.app.member.dao.ISubjectDao;
import com.lianrui.app.member.domain.Subject;
import com.lianrui.app.member.service.ISubjectService;
import com.lianrui.app.member.vos.SubjectPage;
import com.lianrui.commons.exception.BusinessException;
import com.lianrui.core.AbstractService;
import com.lianrui.core.IDao;

@Service("subjectService")
public class SubjectService extends AbstractService<SubjectPage, Subject, Integer>
        implements ISubjectService {

	private static final long serialVersionUID = 1L;

	private static final Logger LOGGER = LoggerFactory.getLogger(SubjectService.class);

    @Autowired
    ISubjectDao subjectDao;
    
    @Override
    public IDao<SubjectPage, Subject, Integer> getDao()
            throws BusinessException {
        // TODO Auto-generated method stub
        return subjectDao;
    }

    @Override
    protected Logger getLogger() {
        // TODO Auto-generated method stub
        return LOGGER;
    }

    @Override
    public void add(Subject d) throws BusinessException {
        SubjectPage page = new SubjectPage();
        Map<String, String> expands = new HashMap<String, String>();
        expands.put("member_id", d.getMember_id().toString());
        page.setExpands(expands);
        int count = this.subjectDao.count(page);
        if (count == 0) {
            d.setIs_default(1);
        }else{
            d.setIs_default(0);
        }
        super.add(d);
    }
    
    

}
